class Sign{
    constructor(){
        this.txt = document.querySelectorAll('.form-control')[0]  //用户名
        this.pass = document.querySelectorAll('.form-control')[1] //密码
        this.box1 = document.querySelector('.box1>input')         //复选框
        this.btn = document.querySelectorAll('button')[0]        //登录
        this.sp = document.querySelector('.form-group>span')
        this.tips = document.querySelector('.tips>span>a') 
        this.tp = document.querySelector('.tips>span')
        this.showname = false
        this.showpass = false                
       this.init()
    }
    init(){
      this.click()
      this.handleBtn()
    }
    click(){
        this.tips.onclick = ()=>{
            location.href='register.html'
        }
    }
    handleBtn(){
        var arr =JSON.parse(localStorage.getItem('inif')) ||[]
        this.btn.onclick = ()=>{
          // 先判断用户名和密码是否被填写
          //判断用户名是否输入
          if(this.txt.value == '' || this.pass.value == ''){
            this.sp.innerHTML = '请输入用户名或密码'
            return
          }
          //判断输入的用户名和密码是否能在localStorage中找到
      
          if(arr.length >0){
            var res = arr.some((item)=>{return item.username == this.txt.value})
      
          }
          if(arr.length >0){
            var err = arr.some((item)=>{return item.password == this.pass.value})
      
          }
          if(res && err){
            localStorage.setItem('info',JSON.stringify(this.txt.value))
            alert('登录成功')
            setTimeout(()=>{
            location.href = '../index.html'
            },1000)
          }else{
            alert ('输入的用户名和密码有误')
          }
      
        }
    }
}
new Sign()
 

 

 
